home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / prim / tabify.el < prev    next >
Encoding:
Text File  |  1995-05-12  |  2.4 KB  |  73 lines

  1. ;;; tabify.el --- tab conversion commands for XEmacs
  2.  
  3. ;; Copyright (C) 1985, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Synched up with: FSF 19.28.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; Commands to optimize spaces to tabs or expand tabs to spaces in a region
  28. ;; (`tabify' and `untabify').  The variable tab-width does the obvious.
  29.  
  30. ;;; Code:
  31.  
  32. ;;;###autoload
  33. (defun untabify (start end)
  34.   "Convert all tabs in region to multiple spaces, preserving columns.
  35. Called non-interactively, the region is specified by arguments
  36. START and END, rather than by the position of point and mark.
  37. The variable `tab-width' controls the spacing of tab stops."
  38.   (interactive "r")
  39.   (save-excursion
  40.     (save-restriction
  41.       (narrow-to-region (point-min) end)
  42.       (goto-char start)
  43.       (while (search-forward "\t" nil t)    ; faster than re-search
  44.     (let ((tab-beg (point))
  45.           (column (current-column))
  46.           (indent-tabs-mode nil))
  47.       (skip-chars-backward "\t" start)
  48.       (delete-region tab-beg (point))
  49.       (indent-to column))))))
  50.  
  51. ;;;###autoload
  52. (defun tabify (start end)
  53.   "Convert multiple spaces in region to tabs when possible.
  54. A group of spaces is partially replaced by tabs
  55. when this can be done without changing the column they end at.
  56. Called non-interactively, the region is specified by arguments
  57. START and END, rather than by the position of point and mark.
  58. The variable `tab-width' controls the spacing of tab stops."
  59.   (interactive "r")
  60.   (save-excursion
  61.     (save-restriction
  62.       (narrow-to-region start end)
  63.       (goto-char start)
  64.       (while (re-search-forward "[ \t][ \t][ \t]*" nil t)
  65.     (let ((column (current-column))
  66.           (indent-tabs-mode t))
  67.       (delete-region (match-beginning 0) (point))
  68.       (indent-to column))))))
  69.  
  70. (provide 'tabify)
  71.  
  72. ;;; tabify.el ends here
  73.